#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2014-2018, Intel Corporation
#
#
# pmempool_info/TEST8 -- test for info command
#

. ../unittest/unittest.sh

require_test_type medium

require_fs_type pmem non-pmem

setup

POOL=$DIR/file.pool
LOG=out${UNITTEST_NUM}.log
rm -f $LOG && touch $LOG

expect_normal_exit $PMEMPOOL$EXESUFFIX create blk 512 $POOL
expect_normal_exit $PMEMWRITE$EXESUFFIX $POOL 1:e 2:w:TEST

INFO_NLBA=$(expect_normal_exit $PMEMPOOL$EXESUFFIX info $POOL | $GREP 'External LBA count' | grep -o '[0-9]\+')
NLBA=$(expect_normal_exit $PMEMPOOL$EXESUFFIX info -m $POOL | $GREP -c '[0-9]\+: 0x[0-9]\+.*')
NZER=$(expect_normal_exit $PMEMPOOL$EXESUFFIX info -mue $POOL | $GREP -c '[0-9]\+: 0x[0-9]\+.*')
NERR=$(expect_normal_exit $PMEMPOOL$EXESUFFIX info -muz $POOL | $GREP -c '[0-9]\+: 0x[0-9]\+.*')
NNON=$(expect_normal_exit $PMEMPOOL$EXESUFFIX info -mez $POOL | $GREP -c '[0-9]\+: 0x[0-9]\+.*')

echo "Number of LBAs: $INFO_NLBA" >> $LOG
echo "Number of LBAs in map: $NLBA" >> $LOG
echo "Number of LBAs [zero]: $NZER" >> $LOG
echo "Number of LBAs [error]: $NERR" >> $LOG
echo "Number of LBAs [no flag]: $NNON" >> $LOG

NSUM=$(($NZER + $NERR + $NNON))
[[ $NSUM == $NLBA ]] || fatal "$NSUM != $NLBA"
[[ $NSUM == $INFO_NLBA ]] || fatal "$NSUM != $INFO_NLBA"

expect_normal_exit $PMEMPOOL$EXESUFFIX info -dz $POOL >> $LOG

check

pass
